﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CommonAliPay;
using System.Web.UI;
using WmWebSystem.DbHelper;
using WmWebSystem.Service;

namespace WmWebSystem.Controllers
{
    public class BeteiligungController : Controller
    {
        //
        // GET: /Beteiligung/
        //您账户的交易安全校验码（key）：7a8s6v12idv9ref2kg3i2g6f430y7zkp 
        //您账户的合作者身份ID（partnerID）：2088002272589021 

        AliPay ap = new AliPay();

        public ActionResult Index()
        {
            var project = ProjectHelper.FindAllProjectByStatus(1);
            ViewData["projects"] = project;
            return View();
        }
        public ActionResult JoinUs(int id, FormCollection colletcion)
        {
            var project = ProjectHelper.FindProjectById(id);
            return View();
        }

        public ActionResult DigitalTrade(int id,FormCollection colletcion) 
        {
            string key = "";//填写自己的key
            string partner = "";//填写自己的Partner
            
            DigitalGoods bp = new DigitalGoods("create_digital_goods_trade_p", partner, key, "MD5", "卡2", Guid.NewGuid().ToString(), 2.551m, 1, "hao_ding2000@yahoo.com.cn", "hao_ding2000@yahoo.com.cn");
            bp.Notify_Url = "http://203.86.79.185/ali/notify.aspx";
            Page current = HttpContext.CurrentHandler as Page;
            ap.CreateDigitalTrade("https://www.alipay.com/cooperate/gateway.do", bp, current);
            return View();
        }

        public ActionResult StandardPay() 
        {
            string key = "";//填写自己的key
            string partner = "";//填写自己的Partner
            StandardGoods bp = new StandardGoods("trade_create_by_buyer", partner, key, "MD5", "卡2", Guid.NewGuid().ToString(), 2.551m, 1, "hao_ding2000@yahoo.com.cn", "hao_ding2000@yahoo.com.cn", "EMS", 25.00m, "BUYER_PAY", "1");
            bp.Notify_Url = "http://203.86.79.185/ali/notify.aspx";
            Page current = HttpContext.CurrentHandler as Page;
            ap.CreateStandardTrade("https://www.alipay.com/cooperate/gateway.do", bp, current);
            return View();
        }
        public ActionResult Notify() 
        {
            string key = "";//填写自己的key
            string partner = "";//填写自己的Partner
            string notifyid = Request.Form["notify_id"];
            Verify v = new Verify("notify_verify", partner, notifyid);
            ap.WaitSellerSendGoods += new AliPay.ProcessNotifyEventHandler(ap_WaitSellerSendGoods);
            ap.WaitBuyerPay += new AliPay.ProcessNotifyEventHandler(ap_WaitBuyerPay);
            Page current = HttpContext.CurrentHandler as Page;
            ap.ProcessNotify(current, "https://www.alipay.com/cooperate/gateway.do", key, v, "utf-8");
            return View();
        }
        private void ap_WaitBuyerPay(object sender, NotifyEventArgs e)
        {
            // //加入自己的处理逻辑
            Log4net.log.Error("wait buyer pay fire");
        }


        private void ap_WaitSellerSendGoods(object sender, NotifyEventArgs e)
        {
            //加入自己的处理逻辑
            Log4net.log.Error("WaitSellerSendGoods fire");
        }



    }
}
